//用户信息数据
function createUserList() {
  return [
    {
      user: {
        createdAt: '2023-12-29T13:48:47+08:00',
        updatedAt: '2023-12-29T05:52:24+08:00',
        uuid: 'bdb8443a-c925-46ed-a27a-9282399d818e',
        userName: 'admin',
        nickName: 'admin',
        avatar: 'https://qmplusimg.henrongyi.top/gva_header.jpg',
        password: '12345',
        phone: '12345',
        email: '12345@qq.com',
        enable: 1,
      },
      token:
        'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJVVUlEIjoiYmRiODQ0M2EtYzkyNS00NmVkLWEyN2EtOTI4MjM5OWQ4MThlIiwiVXNlcm5hbWUiOiJhZG1pbiIsIkJ1ZmZlclRpbWUiOjg2NDAwLCJpc3MiOiJpc3N1ZXIiLCJhdWQiOlsiR1ZBIl0sImV4cCI6MTcwNDU5MzU4MywibmJmIjoxNzAzOTg4NzgzfQ.kaIrf4HegeC7qK2L3ab4lwD8syCbQpYtiUdsbx3L2U4',
      expiresAt: 1704593583000,
    },
  ]
}

export default [
  // 用户登录接口
  {
    url: '/api/user/login', //请求地址
    method: 'post', //请求方式
    response: ({ body }) => {
      //获取请求体携带过来的用户名与密码
      const { username, password } = body
      //调用获取用户信息函数,用于判断是否有此用户
      const checkUser = createUserList().find(
        (item) =>
          item.user.userName === username && item.user.password === password,
      )
      //没有用户返回失败信息
      if (!checkUser) {
        return { code: 201, data: { message: '账号或者密码不正确' } }
      }
      //如果有返回成功信息
      const { token } = checkUser
      return { code: 200, data: { token } }
    },
  },
  // 获取用户信息
  {
    url: '/api/user/info',
    method: 'get',
    response: (request) => {
      //获取请求头携带token
      const token = request.headers.token
      //查看用户信息是否包含有次token用户
      const checkUser = createUserList().find((item) => item.token === token)
      //没有返回失败的信息
      if (!checkUser) {
        return { code: 201, data: { message: '获取用户信息失败' } }
      }
      //如果有返回成功信息
      return { code: 200, data: { checkUser } }
    },
  },
]
